import picocli.CommandLine;
import picocli.CommandLine.Command;
import repository.Repository;

import java.util.Arrays;
import java.util.Set;

@Command(
        name = "jit",
        subcommands = {
                core.JitAdd.class,
                core.JitInit.class,
                core.JitStatus.class,
                core.JitLog.class,
                core.JitRemove.class,
                core.JitCommit.class,
                core.JitReset.class,
                core.JitBranch.class,
                core.JitCheckout.class,
                core.JitDiff.class
        },
        description = "A Git client implemented by Java."
)
public class Jit implements Runnable{
    public static void main(String[] args) {
        var cli = new CommandLine(new Jit());
        // 若需要初始化当前仓库，则向上查找.jit路径
        Set<String> need_init = cli.getSubcommands().keySet();
        need_init.removeAll(Arrays.asList("init"));

        if(args.length >= 1 && need_init.contains(args[0])){
            Repository.lookupRoot();
        }
        cli.execute(args);
    }

    @Override
    public void run() {
        new CommandLine(new Jit()).usage(System.out);
    }
}
